
#include "BallGame.h"

BallGame::BallGame(){
	running = false;
	paused = false;
	gameOver = false;
	won = false;
	displaySurface = NULL;
	testSurface = NULL;

	srand((unsigned int)time(NULL));
}

BallGame::~BallGame(){

}

bool BallGame::toogleFullScreen(){
	
	Uint32 flags = displaySurface->flags;

	if((displaySurface = SDL_SetVideoMode(0,0,16, flags ^ SDL_FULLSCREEN)) == NULL)
	{
		if((displaySurface = SDL_SetVideoMode(0,0,16,flags)) == NULL)
			exit(1);
		return false; //Para evitar warnings
	}
	else
		return true;
}

int BallGame::onExecute(){
	
	if(onInit() == false)
		return -1;
	
	SDL_Event e;

	running = true;

	while(running)
	{
		//Interpreta todos os eventos
		while(SDL_PollEvent(&e))
			CEvent::OnEvent(&e);
		
		onLoop();
		
		onRender();
	}

	onCleanup();

	return 0;
}

void BallGame::OnExit(){
	running = false;
}

void BallGame::resetGame(){

	pontosText.zeraPontos();
	bolasText.setBolas(10);
	item.setVisible(false);
	bola.clearEffectFlags();
	barra.clearEffectFlags();

	while(!CEntity::entityEffects.empty())
		CEntity::entityEffects.pop();

	barra.setPos((float)(WND_WIDTH / 2 - barra.getLarguraBarra() / 2), barra.getPosY());

	paused = false;
	gameOver = false;
	won = false;
	((CBola*)CEntity::entityList[BOLA_INDEX])->setInGame(false);
	gameOverText.setVisivel(false);
	wonText.setVisivel(false);
	level.setLevel(1);
}

